#include <stdio.h>
#include <stdlib.h>
#include "lexer.h"
#include "token.h"
#include "tree.h"
#include "gen.h"

int linenum = 0;
FILE *yyin;
extern char *fname;

int main(int argc, char *argv[])
{
	int t;
	int i = 1;

	instrlist = malloc(sizeof(instruction));
	instrlist->next = NULL;
	currlist = instrlist;
	currlist->next = NULL;

	if (argc < 2) { printf("usage: scan file.dat\n"); exit(-1); }

	yyin = fopen(argv[1], "r");
	if(yyin == NULL)
	{
		printf("can't open/read '%s'\n", argv[1]);
		exit(-1);
	}

	fname = argv[1];

/*		while ((t = yylex()) != 0)
                {
			if(t != EOF)
			{
				printf("%d\t%s\n", t, yytext);
			}
			else
			{
				printf("%d\tEOF\n", t);
				break;
			}
		}
*/

// UNCOMMENT THIS WHEN IMPLEMENTING THE GRAMMAR
	printf("%s\n", fname);
	yyparse();

//	printT(tree, 0);
	TraverseTree(tree);
	PrintList(instrlist);
	printf("END OF PROGRAM\n");

}
